<template>
  <view class="container">
    <button @click="testError">测试错误上报</button>
    <button @click="testCustomError">测试自定义错误</button>
    <button @click="testBehavior">记录用户行为</button>
  </view>
</template>

<script setup lang="ts">
import { inject } from 'vue';
import type { UniErrorSDK } from '@logwisdomhub/uniapp-error-sdk';
import { ErrorLevel } from '@logwisdomhub/uniapp-error-sdk';

const errorSDK = inject<UniErrorSDK>('errorSDK');

function testError() {
  try {
    // 故意制造一个错误
    throw new Error('这是一个测试错误');
  } catch (error) {
    errorSDK?.reportError(error as Error, ErrorLevel.ERROR, {
      action: 'test_error_button',
      page: 'index'
    });
  }
}

function testCustomError() {
  errorSDK?.reportError('自定义错误消息', ErrorLevel.WARNING, {
    customField: '自定义数据',
    userId: '12345'
  });
}

function testBehavior() {
  errorSDK?.recordBehavior('click', {
    element: 'test_behavior_button',
    page: 'index',
    timestamp: Date.now()
  });
}
</script>

<style>
.container {
  padding: 20px;
}

button {
  margin: 10px 0;
  width: 100%;
}
</style>